<template>
  <page-header-wrapper>
    <a-card :bordered="false" class="card_top_padding" style="margin-bottom: 11px">
      <div class="searchBox">
        <a-input placeholder="请输入订单号" v-model="queryParam.order_no">
          <a-icon slot="suffix" type="search" />
        </a-input>
        <a-input placeholder="请输入用户名" v-model="queryParam.name">
          <a-icon slot="suffix" type="search" />
        </a-input>
        <span style="margin-top: 14px; margin-right: 10px">起止时间:</span>
        <a-range-picker
          style="margin-top: 14px"
          :show-time="{ format: 'HH:mm' }"
          format="YYYY-MM-DD HH:mm"
          valueFormat="YYYY-MM-DD HH:mm"
          :placeholder="['开始时间', '结束时间']"
          v-model="queryTime"
          @change="changeTime"
        />
        <a-button type="primary" @click="getOrderList" style="margin-left: 10px">查询</a-button>
        <a-button :loading="exporting" @click="exportOL" type="primary" style="margin-left: 9px">导出Excel</a-button>
      </div>
    </a-card>
    <a-card :bordered="false" class="card_style_re">
      <div class="table-operator" style="display: flex; justify-content: space-between">
        <a-radio-group v-model="queryParam.status" @change="getOrderList">
          <a-radio-button :value="-1"> 全部 </a-radio-button>
          <a-radio-button :value="0"> 待核销 </a-radio-button>
          <a-radio-button :value="1"> 已核销 </a-radio-button>
        </a-radio-group>
        <!-- <a-button>导出报表</a-button> -->
      </div>
      <!-- <a-alert type="info" show-icon style="margin-bottom: 10px">
        <span slot="message">
          已选择 <span style="color: red">{{ selectedRowKeys.length }}</span> 项
        </span>
      </a-alert> -->
      <ListTable ref="listTable" :list_th="list_th" :pagaData="orderList"> </ListTable>
    </a-card>
  </page-header-wrapper>
</template>

<script>
import { clerkOrder, expclerkOrder } from '@/api/outlet'
import ListTable from './components/ListTable'
export default {
  components:{
      ListTable
  },
  data() {
    return {
      exporting: false,
      list_th: [
        { type: 'list', title: '产品名称', span: 5 },
        { type: 'list', title: '单价/数量', span: 3 },
        { type: 'list', title: '订单金额', span: 3 },
        { type: 'list', title: '核销员工', span: 2 },
        { type: 'list', title: '下单时间', span: 4 },
        { type: 'list', title: '核销时间', span: 4 },
        { type: 'list', title: '订单状态', span: 2 },
      ],
      // 查询参数
      queryParam: {
        order_no: null,
        name:null,
        start_time: null,
        end_time: null,
        pageNo: 1,
        pageSize: 10,
        status:-1
      },
      // 核销订单列表
      orderList: [],
      // 数据总条数
      totalCount: 0,
      // 起止时间数组
      queryTime: [],
    }
  },
  methods: {
    exportOL(e) {
      this.exporting = true;
      let parameter = {...this.queryParam};
      Object.assign(parameter, {
        pageNo: 1,
        pageSize: 100000,
        _filename: '核销数据.xlsx',
        export: 1
      })
      expclerkOrder(parameter).then(()=>{
        this.exporting = false;
      });
    },
    // 获取门店列表
    async getOrderList() {
      const res = await clerkOrder(this.queryParam)
      console.log(res)
      if (res.code == 0) {
        this.totalCount = res.data.totalCount
        this.orderList = res.data.data
      }
    },
    // 分页请求
    tablePageChange(e) {
      this.queryParam.pageNo = e
      this.getOrderList()
    },
    // 切换筛选时间
    changeTime(e) {
      if (e.length) {
        this.queryParam.start_time = e[0]
        this.queryParam.end_time = e[1]
      } else {
        this.queryParam.start_time = null
        this.queryParam.end_time = null
      }
    },
  },
  created() {
    this.getOrderList()
  },
}
</script>

<style lang="less" scoped>
.searchBox {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  /deep/ .ant-input-affix-wrapper {
    width: 220px;
    margin-top: 14px;
    margin-right: 20px;
  }
  .select {
    display: flex;
    align-items: center;
    margin-top: 14px;
    margin-right: 20px;
  }
  .ant-btn {
    margin-top: 14px;
  }
}
.name {
  display: flex;
  align-items: center;
  .pic {
    width: 48px;
    min-width: 48px;
    height: 48px;
    border-radius: 4px;
    overflow: hidden;
    margin-right: 24px;
    img {
      width: 100%;
      height: 100%;
    }
  }
  .info {
    flex: auto;
    width: 0;
    display: flex;
    flex-direction: column;
    font-size: 14px;
    span {
      width: 100%;
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
    }
    span:nth-child(2) {
      color: rgba(0, 0, 0, 0.45);
      margin-top: 6px;
    }
  }
}
.status {
  display: flex;
  align-items: center;
  span:nth-child(1) {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    margin-right: 4px;
  }
  .green {
    background-color: #65c817;
  }
  .grey {
    background-color: #c6c6c6;
  }
}
.action {
  display: flex;
  align-items: center;
  .line {
    width: 1px;
    height: 14px;
    background-color: #d8d8d8;
  }
}
</style>